package spring.command.base;

import java.util.HashMap;
import android.util.Log;
import spring.command.MainActivity;
/**
 * @author wanfaxue
 * @date 2012-4-14
 * handler register execute update 
 */
public class CommandCenter extends CommandHandler{
	private static final String TAG = "CommandCenter";
	private HashMap<Integer, CommandHandler> commandsHashMap = new HashMap<Integer, CommandHandler>();
	
	public CommandCenter(MainActivity act){
		activity = act;
	}
	
	/**
	 * register a handle
	 * @param id
	 * @param commandHandler
	 */
	public void register(Integer id, CommandHandler commandHandler){
		Log.d(TAG, "register:"+id);
		if(commandHandler != null){
			commandsHashMap.put(id, commandHandler);
			commandHandler.activity = activity;
		}
	}

	@Override
	public void execute(ICommander commander) {
		CommandHandler cHandler = commandsHashMap.get(commander.getId());
		if(cHandler != null){
			cHandler.execute(commander);
		}
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub
		super.update();
	}
	
	
}
